package com.yimi.yinhepda.entity.response;

import com.yimi.yinhepda.entity.bean.DispatchEntity;
import com.yimi.yinhepda.utils.BigDecimalUtils;

import java.util.List;

/**
 * @author 000432
 * @date 2017/4/20 0020
 */

public class DispatchTaskResponse {

    private List<DispatchTaskEntity> data;
    private boolean success;
    private String[] errorMessages;
    private int errorCode;

    public static class DispatchTaskEntity {
        /**
         * 任务号
         */
        private String taskNo;
        /**
         * 配送任务状态: 1-未配货,2-已配货,3-已确认
         */
        private Integer taskState;
        /**配送任务状态名称*/
        //        private Integer taskStateName;
        /**
         * 配送备注
         */
        private String taskRemark;

        //        private String startTimeStr;//发车时间
        /**
         * 车牌号
         */
        private String carNo;
        /**
         * 车牌编号
         */
        private String carType;
        /**
         * 车型名称
         */
        private String carTypeName;
        /**
         * 容积(限载体积)
         */
        private Double carVolume;
        /**
         * 车次号
         */
        private String carTimeNo;
        /**
         * 派件大区编号
         */
        private String dispatchBigAreaCode;
        /**
         * 派件大区名称
         */
        private String dispatchBigAreaName;
        /**
         * 派件区域编号
         */
        private String dispatchAreaCode;
        /**
         * 派件区域名称
         */
        private String dispatchAreaName;
        /**
         * 司机电话
         */
        private String driverPhone;
        /**
         * 司机姓名
         */
        private String driverName;
        /**
         * 司机工号
         */
        private String driverEmpCode;
        /**
         * 配送网点
         */
        private String deptCode;
        /**
         * 创建人工号
         */
        private String creater;
        /**
         * 创建时间
         */
        private String createrTimeStr;
        /**
         * 所属公司
         */
        private String compCode;
        /**
         * 配送运单集合
         */
        private List<DispatchEntity> soonList;
        /**
         * 删除标志：1-删除，0-未删除
         */
        private Integer isDelete;

        private boolean isChecked;

        public List<DispatchEntity> getSoonList() {
            return soonList;
        }

        public Integer getIsDelete() {
            return isDelete;
        }

        public void setIsDelete(Integer isDelete) {
            this.isDelete = isDelete;
        }

        public void setSoonList(List<DispatchEntity> soonList) {
            this.soonList = soonList;
        }

        public String getCompCode() {
            return compCode;
        }

        public void setCompCode(String compCode) {
            this.compCode = compCode;
        }

        public String getTaskNo() {
            return taskNo;
        }

        public void setTaskNo(String taskNo) {
            this.taskNo = taskNo;
        }

        public Integer getTaskState() {
            if (taskState == null) {
                taskState = 0;
            }
            return taskState;
        }

        public String getDispatchAreaCode() {
            return dispatchAreaCode;
        }

        public void setDispatchAreaCode(String dispatchAreaCode) {
            this.dispatchAreaCode = dispatchAreaCode;
        }

        public String getDispatchAreaName() {
            return dispatchAreaName;
        }

        public void setDispatchAreaName(String dispatchAreaName) {
            this.dispatchAreaName = dispatchAreaName;
        }

        public void setTaskState(Integer taskState) {
            this.taskState = taskState;
        }

        public String getTaskRemark() {
            return taskRemark;
        }

        public void setTaskRemark(String taskRemark) {
            this.taskRemark = taskRemark;
        }

        public String getCarNo() {
            return carNo;
        }

        public void setCarNo(String carNo) {
            this.carNo = carNo;
        }

        public String getCarType() {
            return carType;
        }

        public void setCarType(String carType) {
            this.carType = carType;
        }

        public String getCarTypeName() {
            return carTypeName;
        }

        public void setCarTypeName(String carTypeName) {
            this.carTypeName = carTypeName;
        }

        public Double getCarVolume() {
            if (carVolume == null) {
                carVolume = 0.0;
            }
            return carVolume;
        }

        public void setCarVolume(Double carVolume) {
            this.carVolume = carVolume;
        }

        public String getCarTimeNo() {
            return carTimeNo;
        }

        public void setCarTimeNo(String carTimeNo) {
            this.carTimeNo = carTimeNo;
        }

        public String getDispatchBigAreaCode() {
            return dispatchBigAreaCode;
        }

        public void setDispatchBigAreaCode(String dispatchBigAreaCode) {
            this.dispatchBigAreaCode = dispatchBigAreaCode;
        }

        public String getDispatchBigAreaName() {
            return dispatchBigAreaName;
        }

        public void setDispatchBigAreaName(String dispatchBigAreaName) {
            this.dispatchBigAreaName = dispatchBigAreaName;
        }

        public String getDriverPhone() {
            return driverPhone;
        }

        public void setDriverPhone(String driverPhone) {
            this.driverPhone = driverPhone;
        }

        public String getDriverName() {
            return driverName;
        }

        public void setDriverName(String driverName) {
            this.driverName = driverName;
        }

        public String getDriverEmpCode() {
            return driverEmpCode;
        }

        public void setDriverEmpCode(String driverEmpCode) {
            this.driverEmpCode = driverEmpCode;
        }

        public String getDeptCode() {
            return deptCode;
        }

        public void setDeptCode(String deptCode) {
            this.deptCode = deptCode;
        }

        public String getCreater() {
            return creater;
        }

        public void setCreater(String creater) {
            this.creater = creater;
        }

        public String getCreaterTimeStr() {
            return createrTimeStr;
        }

        public void setCreaterTimeStr(String createrTimeStr) {
            this.createrTimeStr = createrTimeStr;
        }

        public boolean isChecked() {
            return isChecked;
        }

        public void setChecked(boolean checked) {
            isChecked = checked;
        }
    }

    public List<DispatchTaskEntity> getData() {
        return data;
    }

    public void setData(List<DispatchTaskEntity> data) {
        this.data = data;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String[] getErrorMessages() {
        return errorMessages;
    }

    public void setErrorMessages(String[] errorMessages) {
        this.errorMessages = errorMessages;
    }

    public int getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(int errorCode) {
        this.errorCode = errorCode;
    }

    public static int getTotalPiaoNum(List<DispatchEntity> data) {
        if (data == null || data.size() <= 0) {
            return 0;
        }
        return data.size();
    }

    public static int getTotalJianNum(List<DispatchEntity> data) {
        if (data == null || data.size() <= 0) {
            return 0;
        }
        int result = 0;
        for (DispatchEntity entity : data) {
            result += entity.getQuantity();
        }
        return result;
    }

    /**
     * 总重量
     */
    public static Double getTotalWeight(List<DispatchEntity> data) {
        if (data == null || data.size() <= 0) {
            return 0.0;
        }
        Double result = 0.0;
        for (DispatchEntity entity : data) {
            result += entity.getRealWeightQty();
        }
        return result;
    }

    /**
     * 总体积
     */
    public static Double getTotalVolume(List<DispatchEntity> data) {
        if (data == null || data.size() <= 0) {
            return 0.0;
        }
        Double result = 0.0;
        for (DispatchEntity entity : data) {
            result += entity.getVolume();
        }
        return result;
    }

    /**
     * 总已扫描票数
     */
    public static int getScannedPiao(List<DispatchEntity> data) {
        if (data == null || data.size() <= 0) {
            return 0;
        }
        int count = 0;
        List<DispatchScanResponse.DispatchWaybillChild> childList;
        for (DispatchEntity item : data) {
            childList = item.getChildList();
            if (childList == null) {
                continue;
            }
            for (DispatchScanResponse.DispatchWaybillChild childItem : childList) {
                if (childItem.getFlag() == 1) {
                    count++;
                    break;//加一次就好，退出当前for循环，继续
                }
            }
        }
        return count;
    }

    /**
     * 已经扫描总件数
     */
    public static int getScannedJian(List<DispatchEntity> data) {
        if (data == null || data.size() <= 0) {
            return 0;
        }
        int count = 0;
        for (DispatchEntity entity : data) {
            count += entity.getScanCount();
        }
        return count;
    }

    /**
     * 扫描件的总真实重量
     */
    public static Double getScannedWeight(List<DispatchEntity> data) {
        if (data == null || data.size() <= 0) {
            return 0.0;
        }
        Double result = 0.0;
        int count = 0;
        for (DispatchEntity entity : data) {
            count = entity.getScanCount();
            result += BigDecimalUtils.mul(BigDecimalUtils.div(entity.getRealWeightQty(), entity.getQuantity(), 4), count);
        }
        return result;
    }

    /**
     * 扫描件的总体积
     */
    public static Double getScannedVolume(List<DispatchEntity> data) {
        if (data == null || data.size() <= 0) {
            return 0.0;
        }
        Double result = 0.0;
        int count = 0;
        for (DispatchEntity entity : data) {
            count = entity.getScanCount();
            result += BigDecimalUtils.mul(BigDecimalUtils.div(entity.getVolume(), entity.getQuantity(), 4), count);
        }
        return result;
    }

    /**
     * 扫描件的总计费重量
     */
    public static Double getScannedChargeableWeight(List<DispatchEntity> data) {
        if (data == null || data.size() <= 0) {
            return 0.0;
        }
        Double result = 0.0;
        int count = 0;
        for (DispatchEntity entity : data) {
            count = entity.getScanCount();
            result += BigDecimalUtils.mul(BigDecimalUtils.div(entity.getMeterageWeightQty(), entity.getQuantity(), 4), count);
        }
        return result;
    }
}
